package com.jnu.hc.jnuhcusercms.service;

import com.jnu.hc.jnuhcusercms.domain.Users;
import com.jnu.hc.jnuhcusercms.dto.ResponseObject;
import com.jnu.hc.jnuhcusercms.exception.HcAPPException;
import com.jnu.hc.jnuhcusercms.mapper.UsersMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    UsersMapper usersMapper;


    @Override
    public ResponseObject<Users> saveUsers(Users users){
        //先查看用户表中有没有该用户
        Users result = usersMapper.selectByPrimaryKey(users.getUserId());
        System.out.println(result);
        System.out.println(users.getIdentityCard());
        if(result!=null){
            //告诉前端该手机号已经存在
            throw new HcAPPException(2002,
                    "该手机号已经存在");
        }
        usersMapper.insert(users);
        return new ResponseObject(ResponseObject.SUCCESS_STATUS,ResponseObject.SUCCESS_DESC,users);
    }
}
